package at.tuwien.seminar.scrum1.view.bill.list;

import at.tuwien.seminar.scrum1.configuration.Configuration;
import at.tuwien.seminar.scrum1.model.Bill;
import at.tuwien.seminar.scrum1.model.Customer;
import at.tuwien.seminar.scrum1.model.Room;
import at.tuwien.seminar.scrum1.provider.DataProvider;
import at.tuwien.seminar.scrum1.proxies.BillProxy;
import at.tuwien.seminar.scrum1.proxies.ReservationProxy;
import at.tuwien.seminar.scrum1.proxies.RoomProxy;
import at.tuwien.seminar.scrum1.view.customer.list.CustomerList;
import at.tuwien.seminar.scrum1.view.reservation.list.ReservationList;
import at.tuwien.seminar.scrum1.view.room.create.CreateRoom;
import at.tuwien.seminar.scrum1.view.room.list.RoomList;
import at.tuwien.seminar.scrum1.view.titlepage.TitlePage;
import at.tuwien.seminar.scrum1.view.wicket.column.CustomerColumn;
import at.tuwien.seminar.scrum1.view.wicket.room.ReservationActionPanel;
import at.tuwien.seminar.scrum1.view.wicket.room.RoomDeleteActionPanel;
import at.tuwien.seminar.scrum1.view.wicket.room.RoomUpdateActionPanel;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DefaultDataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import java.util.ArrayList;
import java.util.List;

public class BillList extends WebPage {

	public BillList() {

        add(new Link<Room>("roomLink") {

			@Override
			public void onClick() {
				setResponsePage(new RoomList());
			}

		});
		add(new Link<Customer>("customerLink") {

			@Override
			public void onClick() {
				setResponsePage(new CustomerList());
			}

		});

        add(new Link<Customer>("reservationLink") {

			@Override
			public void onClick() {
				setResponsePage(new ReservationList(ReservationProxy.getInstance().getAll()));
			}

		});

         add(new Link<Bill>("billLink") {

			@Override
			public void onClick() {
				setResponsePage(new BillList());
			}

		});

		final SortableDataProvider<Bill> dataProvider = new DataProvider<Bill>(
				"id", BillProxy.getInstance().getAll());

		List<IColumn<Bill>> columns = new ArrayList<IColumn<Bill>>();

		columns.add(new PropertyColumn<Bill>(new Model<String>("Rechnungsnummer"), "id",
				"id"));
		columns.add(new PropertyColumn<Bill>(
				new Model<String>("Preis"), "price",
				"price"));
		columns.add(new PropertyColumn<Bill>(new Model<String>(
				"Datum"), "billDate", "billDate"));

        columns.add(new CustomerColumn<Bill>(new Model<String>("Kunde")));



		add(new DefaultDataTable<Bill>("datatable", columns, dataProvider,
                Configuration.ROWSPERPAGE));

		add(new Link<Room>("back") {

			@Override
			public void onClick() {
				setResponsePage(new TitlePage());

			}
		});
		
		add(new Link<Customer>("newRoomLink") {

			@Override
			public void onClick() {
				setResponsePage(new CreateRoom());
			}

		});
	}
}
